<!-- 客服管理 -->
<template>
<div v-if="Visible" class="box">
    <div class="box_Left">
        <div class="search">
            <el-input
                clearable
                v-model="contactSearch"
            >
                <el-button slot="append" icon="el-icon-search" @click="search"></el-button>
            </el-input>
        </div>
        <div @click="openContact(item)" class="contactList_item" :class="item.name==contactName?'active':''" v-for="item in contactList" :key="item.id">{{item.name}}</div>
    </div>
    <div class="box_Right">
        <div class="title">
            <div>{{contactName}}</div>
            <i style="cursor: pointer;" class="el-icon-close" @click="close"></i>
        </div>
        <div class="chat_box" id="mess_content" @scroll="scrollToBottom">
            <div
            v-for="(item, index) in chat_box_text"
            :key="index"
            class="chat_box_item"
            >
            <!--其他用户的消息展示-->
            <div v-if="item.msgType == 1" class="content_other">
                <el-avatar class="userImg" shape="square" size="medium" :src="item.imgUrl"></el-avatar>
                <div style="width:50%;">
                    <div class="userGroup">
                        <span class="username">{{ item.sendName }}</span>
                        <span class="usertime">{{ item.time }}</span>
                    </div>
                    <p class="userMsg">
                        {{ item.msg }}
                    </p>
                </div>
            </div>
            <!-- 本用户的消息展示-->
            <div v-else class="content_me">
                <el-avatar class="userImg" shape="square" size="medium" :src="item.imgUrl"></el-avatar>
                <div style="display: flex;flex-direction: column;align-items: flex-end;width:50%;">
                    <div class="userGroup">
                        <span class="usertime">{{ item.time }}</span>
                    </div>
                    <p class="userMsg">
                        {{ item.msg }}
                    </p>
                </div>
            </div>
            </div>
        </div>
        <div class="input_box">
            <el-input
                resize="none"
                type="textarea"
                placeholder="请输入内容"
                v-model="input_value">
            </el-input>
            <i style="cursor: pointer;" class="el-icon-s-promotion sendBtn" @click="sendInput"></i>
        </div>
    </div>

</div>
</template>

<script>
export default {
  components: {
  },
  data(){
    return{
        Visible:false,
        contactSearch:'',
        contactName:'',
        contactList:[
            {id:0,name:'ceshi0'},
            {id:1,name:'ceshi1'},
            {id:2,name:'ceshi2'},
            {id:3,name:'ceshi3'},
        ],
        chat_box_text:[
            {msgType:1,sendName:'ceshi0',time:'2024-7-8',msg:'211111111211111111211111111211111111',imgUrl:'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'},
            {msgType:0,sendName:'ceshi1',time:'2024-7-8',msg:'211111111211111111211111111211111111',imgUrl:'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'},
            {msgType:1,sendName:'ceshi2',time:'2024-7-8',msg:'211111111211111111211111111211111111',imgUrl:'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'},
            {msgType:0,sendName:'ceshi3',time:'2024-7-8',msg:'211111111211111111211111111211111111',imgUrl:'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'},
            {msgType:1,sendName:'ceshi4',time:'2024-7-8',msg:'211111111211111111211111111211111111',imgUrl:'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'},
            {msgType:0,sendName:'ceshi5',time:'2024-7-8',msg:'211111111211111111211111111211111111',imgUrl:'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'},
        ],
        input_value:''
    }
  },
  computed: {
  },
  mounted(){
  },
  methods:{
    init(){
        this.Visible=true
    },
    search(){
        console.log(this.contactSearch)
    },
    openContact(data){
        this.contactName=data.name
    },
    scrollToBottom(){

    },
    sendInput(){
        let obj={
            msgType:0,
            sendName:'',
            time:this.setDay(),
            msg:this.input_value,
            imgUrl:'https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png'
        }
        this.chat_box_text.push(obj)
        this.input_value=''
    },
    close(){
        this.Visible=false
    },




















    //格式化当前时间
    setDay() {
        var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        let day =
            year +
            seperator1 +
            month +
            seperator1 +
            strDate 
        return day
    },
  }
}
</script>
<style scoped lang="less">
    .box{
        position: fixed;
        right: 10px;
        bottom: 10px;
        z-index: 99999;
        background: #f0f0f0;
        width: 700px;
        height: 500px;
        padding: 0 !important;
        margin: 15px;
        margin-left: 0;
        display: flex;
        flex-direction: row;
        border: 1px solid #ccc;
        border-radius: 5px;
        .box_Left{
            width: 200px;
            height: 100%;
            overflow-y: auto;
            overflow-x: hidden; 
            box-shadow: rgb(230, 223, 223) 7px 0px 8px;
            background-color: #fff;
            border-top-left-radius: 4px;
            border-bottom-left-radius: 4px;
            .search{
                border-bottom: 1px solid #ccc;
                padding: 10px;
                /deep/ .el-input-group--append .el-input__inner{
                    border-top-left-radius: 4px !important;
                    border-bottom-left-radius: 4px !important;
                }
                /deep/ .el-input-group__append{
                    padding: 0;
                    .el-button{
                        margin: 0;
                        padding: 5px 15px;
                    }
                }
            }
            .contactList_item{
                height: 20px;
                line-height: 20px;
                padding: 10px;
                font-size: 18px;
                cursor: pointer;
            }
            .contactList_item.active {
                color: white !important;
                background: #3989fa !important;
                border-radius: 4px;
            }
        }
        .box_Right{
            display: flex;
            flex-direction: column;
            border-left: 1px solid #ccc;
            width: calc(100% - 202px);
            border-top-right-radius: 4px;
            .title{
                display: flex;
                align-items: center;
                justify-content: space-between;
                height: 46px;
                padding: 0 10px;
                border-bottom: 1px solid #ccc;
                background-color: #fff;
            }
            .chat_box{
                flex: 1;
                padding: 10px;
                overflow-y: scroll;
                .chat_box_item{
                    margin-left: 5px;
                    margin-bottom: 10px;
                    .content_other{
                        display: flex;
                        gap: 5px;
                        .userMsg:before {
                            left: -10px;
                            border-color:transparent #fff transparent transparent; /* 筋头颜色 */
                        }
                    }
                    .content_me{
                        display: flex;
                        gap: 5px;
                        flex-direction: row-reverse;
                        .userMsg{
                            background-color: #89d961;
                        }
                        .userMsg:before {
                            right: -10px;
                            border-color:transparent transparent transparent #89d961; /* 筋头颜色 */
                        }
                    }
                    .userImg{
                        margin-top: 5px;
                    }
                    .userGroup{
                        display: flex;
                        gap: 10px;
                        align-items: flex-end;
                        margin-bottom: 5px;
                        .username{
                            font-size: 16px;
                        }
                        .usertime{
                            font-size: 12px;
                            color: #aaa;
                        }
                    }
                    .userMsg{
                        position: relative;
                        max-width: 95%;
                        background-color: #fff;
                        color: #000;
                        border-radius: 6px;
                        padding: 5px;
                        margin-left: 5px;
                        word-wrap: break-word;
                    }
                    .userMsg:before {
                        content:'';
                        position: absolute;
                        top: 5px;
                        border-width:5px;/*箭头大小*/
                        border-style:solid;/*箭头样式*/
                        border-color:transparent #fff transparent transparent; /* 筋头颜色 */
                    }
                }
            }
            .chat_box::-webkit-scrollbar{
                width: 0;
                height: 0;
            }
            .input_box{
                position: relative;
                background-color: #fff;
                /deep/ .el-textarea {
                    padding-bottom: 50px;
                    .el-textarea__inner{
                        min-height: 60px !important;
                        border-radius: 0;
                        border-bottom-right-radius: 4px;
                        border: 0;
                        border-top: 1px solid #DCDFE6;
                    }
                    .el-textarea__inner:focus{
                        border-color: #DCDFE6;
                    }
                    .el-textarea__inner::-webkit-scrollbar{
                        width: 0;
                        height: 0;
                    }
                }
                .sendBtn{
                    position: absolute;
                    right: 10px;
                    bottom: 10px;
                    font-size: 35px;
                    color: #6c9ee5;
                }
            }
        }
    }
</style>